package cn.edu.hbwe.book.utils;

import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class CheckImageServlet
 */
@WebServlet("/imageCode")
public class CheckImageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("UTF-8");
		//1.获取验证码图片
		VerifyCode vf = new VerifyCode();
		BufferedImage image = vf.createImage();
		//2.得到验证码的四个随机数
		String code = vf.getText();
		//为了进项验证码校验
		request.getSession().setAttribute("serverCode", code);
		//3.把验证码输入到页面
		VerifyCode.output(image, response.getOutputStream());
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
